package com.haiyou.dc.string;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.*;

public class ObjectSeriaDemo {

    public static void main(String[] args) throws Exception {
        String file = "obj.dat";
        //序列化
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
        Student stu = new Student("10001", "张三", 20);
        oos.writeObject(stu);
        oos.flush();
        oos.close();
        //反序列化
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
        Student stu1 = (Student) ois.readObject();
        System.out.println(stu1);
        ois.close();
    }

    @Data
    @AllArgsConstructor
    static class Student implements Serializable {
        private String stuno;
        private String stuname;
        //该元素不会进行jvm默认的序列化
        private transient int stuage;
    }
}
